package com.it.myh.query.probability;

import java.io.Serializable;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: // 类说明，在创建类时要填写
 * @ClassName: TimeZone    // 类名，会自动填充
 * @Author: MYH          // 创建者
 * @Date: 2023/6/19 11:24   // 时间
 * @Version: 1.0     // 版本
 */
public class TimeZone implements Serializable {

    private static final long serialVersionUID = -4623247806811216200L;

    private LocalTime startTime;

    private LocalTime endTime;

    private Integer num;//时区的总数

    public TimeZone(LocalTime startTime, LocalTime endTime, Integer num) {
        this.startTime = startTime;
        this.endTime = endTime;
        this.num = num;
    }

    public TimeZone(LocalTime startTime, LocalTime endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    //划分时区
    public static final TimeZone ZONE1 = new TimeZone(LocalTime.parse("00:00:00"),LocalTime.parse("04:59:59")); //凌晨 记录数为：6811757
    public static final TimeZone ZONE2 = new TimeZone(LocalTime.parse("05:00:00"),LocalTime.parse("07:59:59")); //早上 记录数为：4017598
    public static final TimeZone ZONE3 = new TimeZone(LocalTime.parse("08:00:00"),LocalTime.parse("10:59:59")); //上午 记录数为：4980386
    public static final TimeZone ZONE4 = new TimeZone(LocalTime.parse("11:00:00"),LocalTime.parse("12:59:59")); //中午 记录数为：2778035
    public static final TimeZone ZONE5 = new TimeZone(LocalTime.parse("13:00:00"),LocalTime.parse("16:59:59")); //下午 记录数为：3266096
    public static final TimeZone ZONE6 = new TimeZone(LocalTime.parse("17:00:00"),LocalTime.parse("18:59:59")); //傍晚 记录数为：820309
    public static final TimeZone ZONE7 = new TimeZone(LocalTime.parse("19:00:00"),LocalTime.parse("23:59:59")); //晚上 记录数为：2202797

    //给定时间，去判断属于哪个时区
    public static TimeZone whichZone(LocalTime time){
        List<TimeZone> zones = Arrays.asList(ZONE1,ZONE2,ZONE3,ZONE4,ZONE5,ZONE6,ZONE7);
        for (TimeZone zone : zones) {
            if (isBelongZone(time,zone)){
                return zone;
            }
        }
        return null;
    }

    //判断时间是否在指定时区内
    public static boolean isBelongZone(LocalTime time,TimeZone timeZone){
        return !time.isBefore(timeZone.startTime) && !time.isAfter(timeZone.endTime);
    }

    @Override
    public String toString() {
        return "startTime=" + startTime +
                ", endTime=" + endTime +
                ", num=" + num;
    }
    //给定两个时区，判断是否是同一个时区
    public static boolean isSameTimeZone(TimeZone zone1, TimeZone zone2){
        return zone1.startTime == zone2.startTime && zone1.endTime == zone2.endTime;
    }
}
